{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-8.58874715e+01,  1.17803506e-01,  8.98753024e-04,  1.02003285e+01])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from scipy.optimize import curve_fit\n",
    "\n",
    "from sklearn.metrics import r2_score\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "#run sin_decay_test_data.py # set t, y_meas, y_true\n",
    "\n",
    "A, B, C, D = 1, .2, 1.4, 10\n",
    "\n",
    "\n",
    "def Fn(t, A, B, C, D):\n",
    "    return A*np.exp(-B*t)*np.sin(C*t) + D\n",
    "\n",
    "np.random.seed(234567)\n",
    "n_pts = 1000\n",
    "t = np.linspace(1,20,n_pts) + .3*np.random.rand(n_pts)\n",
    "y_true = Fn(t, A, B, C, D)\n",
    "y_meas = y_true + .11*(0.5 - np.random.rand(n_pts))\n",
    "\n",
    "popt, pcov = curve_fit(Fn,t,y_meas)\n",
    "\n",
    "y_curve_fit = Fn(t, *popt)\n",
    "    \n",
    "popt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.03306939199372205"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " r2_score(y_meas, y_curve_fit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
